import java.util.Arrays;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: 冯若航
 * \* Date: 2021/5/12
 * \* Time: 2:38
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class 最小差 {
    public int smallestDifference(int[] a, int[] b){
        Arrays.sort(a);
        Arrays.sort(b);
        int i=0,j=0;
        long min=Integer.MAX_VALUE;
        while (i<a.length&&j<b.length){
            if(a[i]==b[j]){
                return 0;
            }else if(a[i]>b[j]){
                min=Math.min(min,a[i]-b[j]);
                j++;
            }else {
                min = Math.min(min,(long) b[j] -(long) a[i]);
                i ++;
            }
        }
        return (int)min;
    }
}